package com.jz.community.modulemine.money.presenter;

import com.jz.community.basecomm.bean.BaseResponseInfo;
import com.jz.community.basecomm.mvp.BaseLifeCyclePresent;
import com.jz.community.basecomm.net.rxandroid.OnLoadListener;
import com.jz.community.modulemine.money.bean.MoneyExchangeCodeBean;
import com.jz.community.modulemine.money.model.MoneyModel;
import com.jz.community.modulemine.money.model.MoneyModelImp;
import com.jz.community.modulemine.money.ui.MoneyExchangeView;

public class MoneyExchangePresenter extends BaseLifeCyclePresent<MoneyExchangeView.View> implements MoneyExchangeView.Presenter {

    private MoneyExchangeView.View view;
    private MoneyModel moneyModel;

    public MoneyExchangePresenter(MoneyExchangeView.View view) {
        this.view = view;
        this.moneyModel = new MoneyModelImp(view.getContext());
    }


    @Override
    public void initExchangeInfo(String code) {
        moneyModel.initCodeInfo(code, new OnLoadListener<MoneyExchangeCodeBean>() {
            @Override
            public void onSuccess(MoneyExchangeCodeBean moneyExchangeCodeBean) {
                view.getCodeSuccess(moneyExchangeCodeBean);
            }

            @Override
            public void onFail(String msg, int code) {
                view.getCodeFail(msg);

            }
        });

    }

    @Override
    public void exchangeMoney(String code) {
        moneyModel.exchangeMoney(code, new OnLoadListener<BaseResponseInfo>() {
            @Override
            public void onSuccess(BaseResponseInfo baseResponseInfo) {
                view.exchangeSuccess();
            }

            @Override
            public void onFail(String msg, int code) {
                view.exchangeFail(code, msg);

            }
        });

    }
}
